package org.emergency.framework.action.sys;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import javax.annotation.Resource;

import org.emergency.framework.action.BaseAction;
import org.emergency.framework.model.TbPermission;
import org.emergency.framework.model.TbRole;
import org.emergency.framework.service.common.IRolePermissionMapping;
import org.emergency.framework.service.oa.ITbPermissonService;
import org.emergency.framework.service.sys.TableFormBean;
import org.emergency.framework.serviceImpl.common.RolePermissionMappingImpl;
import org.springframework.stereotype.Repository;

import com.opensymphony.oscache.util.StringUtil;


@Repository("tbInputAction")
public class TbInputAction extends BaseAction {

	/**
	 * 返回的信息
	 */
	private String message;

	/**
	 * 表名
	 */
	private String tableName;

	/**
	 * 
	 */
	private String tableCode;

	/**
	 * 字段名，为一逗号隔开的字符串
	 */
	private String columnsName;

	/**
	 * 字段Code，为一逗号隔开的字符串,与columnsName一一对应
	 */
	private String columnsCode;

	/**
	 * 字段类型
	 */
	private String columnsType;

	/**
	 * @return the tableName
	 */
	public String getTableName() {
		return tableName;
	}

	/**
	 * @param tableName
	 *            the tableName to set
	 */
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	/**
	 * @return the tableCode
	 */
	public String getTableCode() {
		return tableCode;
	}

	/**
	 * @param tableCode
	 *            the tableCode to set
	 */
	public void setTableCode(String tableCode) {
		this.tableCode = tableCode;
	}

	/**
	 * @return the columnsName
	 */
	public String getColumnsName() {
		return columnsName;
	}

	/**
	 * @param columnsName
	 *            the columnsName to set
	 */
	public void setColumnsName(String columnsName) {
		this.columnsName = columnsName;
	}

	/**
	 * @return the columnsCode
	 */
	public String getColumnsCode() {
		return columnsCode;
	}

	/**
	 * @param columnsCode
	 *            the columnsCode to set
	 */
	public void setColumnsCode(String columnsCode) {
		this.columnsCode = columnsCode;
	}

	/**
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @param message
	 *            the message to set
	 */
	public void setMessage(String message) {
		this.message = message;
	}
	

	/**
	 * @return the columnsType
	 */
	public String getColumnsType() {
		return columnsType;
	}

	/**
	 * @param columnsType the columnsType to set
	 */
	public void setColumnsType(String columnsType) {
		this.columnsType = columnsType;
	}

	/**
	 * 增加表
	 * 
	 * @return
	 */
	public String addTable() {
		System.out.println("hello,Actions");
		
		TableFormBean tableFormBean = new TableFormBean();
		tableFormBean.setTableName(tableName);
		tableFormBean.setTableCode(tableCode);
		
		String[] columnsNameArray = columnsName.split(",");
		tableFormBean.setTableColumnsName(Arrays.asList(columnsNameArray));
		
		String[] columnsCodeArray = columnsCode.split(",");
		tableFormBean.setTableColumnsCode(Arrays.asList(columnsCodeArray));
		
		String[] columnsTypeArray = columnsType.split(",");
		tableFormBean.setTableColumnsType(Arrays.asList(columnsTypeArray));
		
		

		if (saveTable(tableFormBean))
			setMessage("增加成功");
		else
			setMessage("增加失败");

		return "addTableSucc";
	}

	
	//处理进来的数据
	private boolean saveTable(TableFormBean tableFormBean) {
		
		System.out.println(tableFormBean);

		return false;
	}

}
